package cn.zyl.demo.common.boot.tools;

import cn.zyl.demo.common.boot.abs.AbsResCode;
import cn.zyl.demo.common.boot.beans.ResBody;
import cn.zyl.demo.common.boot.enums.ResCodeEnum;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/** ResBodyTool工具类说明:响应工具类
 * @author wsz
 * @date 2020-07-31
 * @version v1.0
 */
public class ResBodyTool {
    private ResBodyTool(){throw new IllegalAccessError("ResBodyTool");}
    public static <T> ResBody<T> build(AbsResCode resCode, T data){
        return new ResBody<>(resCode, data);
    }
    public static ResBody<String> success(){
        return new ResBody<>(ResCodeEnum.SUCCESS, "");
    }
    public static <T> ResBody<T> success(T data){
        return new ResBody<>(ResCodeEnum.SUCCESS, data);
    }
    public static ResBody<List<String>> successList(){
        return new ResBody<>(ResCodeEnum.SUCCESS, new ArrayList<>(0));
    }
    public static ResBody<Map<String,String>> successMap(){ return new ResBody<>(ResCodeEnum.SUCCESS, new HashMap<>(0)); }
    public static ResBody<String> fail(){
        return new ResBody<>(ResCodeEnum.FAIL, "");
    }
    public static ResBody<String> fail(AbsResCode resCode){
        return new ResBody<>(resCode, "");
    }
    public static ResBody<String> fail(Throwable e){
        return new ResBody<>(ResCodeEnum.FAIL, e.getMessage());
    }
    public static ResBody<String> error(){
        return new ResBody<>(ResCodeEnum.ERROR, "");
    }
    public static ResBody<String> error(AbsResCode resCode){
        return new ResBody<>(resCode, "");
    }
    public static ResBody<String> error(AbsResCode resCode,String msg){
        return new ResBody<>(resCode, msg);
    }
    public static ResBody<String> error(Throwable e){
        return new ResBody<>(ResCodeEnum.ERROR, e.getMessage());
    }
    public static ResBody<List<String>> failList(){
        return new ResBody<>(ResCodeEnum.FAIL, new ArrayList<>(0));
    }
    public static ResBody<Map<String,String>> failMap(){
        return new ResBody<>(ResCodeEnum.FAIL, new HashMap<>(0));
    }
}